package com.jiefeng.manager.service.dataexcel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 数据Excel导入导出服务接口
 *
 * Created by WuZhiqi on 2016/5/26.
 */
public abstract class DataExcelService<T> {

    private static final Logger logger = LoggerFactory.getLogger(DataExcelService.class);

    public static enum  EXCEL_VERSION { VERSION_XLS, VERSION_XLSX }

    private static Map<Class, DataExcelService> mapper = new ConcurrentHashMap<Class, DataExcelService>();

    public DataExcelService(Class<T> clazz){
        logger.info(String.format("|init|进行初始化: %s", this.getClass().getCanonicalName()));
        if(null == mapper.get(clazz)){
            mapper.put(clazz, this);
        }
    }

    public static <M> DataExcelService<M> getInstance(Class<M> dateType){
        return mapper.get(dateType);
    }

    /**
     * 导出Excel模板
     *
     * @param outputStream
     */
    public abstract void  exportExcelTemplate(OutputStream outputStream, EXCEL_VERSION excelVersion);

    /**
     * 数据导入模板导出
     *
     * @param outputStream
     */
    public abstract void  exportExcel(List<T> exportList, OutputStream outputStream, EXCEL_VERSION excelVersion);


    public abstract void importExcel(File file);

}
